//************************************************
//  *Author：jxx
//  *QQ：283591387
//  *自定义业务逻辑扩展
//************************************************
export default function () {
	return {
		methods: {
			onInited() {
				//页面参数初始化
				//设置table超出换行显示
				//this.textInline = false;
				//设置列宽度
				//this.columns[1].width = 70;
				//设置table为水平显示或者list列表显示
				//this.direction = 'horizontal'//list
				//如果为list列表显示，指定list的标题列
				//this.titleField="字段";
				//设置自定义格式显示
				//this.columns.forEach(column=>{
				// 	if(column.field=='字段'){
				//      //自定义格式化显示,在下面的formatter实现具体逻辑
				// 		//column.formatter=true;
				//      //开启table单元格点击事件(仅设置this.direction = 'horizontal属性后生效)
				//      column.click=true;
				//      //指定字段为date类型不显示时分秒
				//      //column.type="date";
				//      //设置列宽度
				//      //column.width = 70;
				// 	}
				// })
				//页面打开时禁用加载数据
				//this.load=false;
				//页面打开时默认弹出查询框
				//this.searchModel = true;
			},
			formatter(row, column, index) {
				//自定义格式化
				// if(column.field=='xx'){
				//  return '<a style="color:red;">' + row[column.field] + '</a>';
				// }
				//return row[column.field]
			},
			rowClick(index, row, column) {
				//行点击事件(默认触发编辑)
				//获取省信息stater
				// let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=D39479C4-1A27-43BE-8B27-739EB5CEA278`;
				// this.http.post(url, {}).then((result) => {
				// 	let ProvinceList = result.map((a) => {
				// 		return {
				// 			key: a.citys_Id,
				// 			value: a.citys_name
				// 		};
				// 	});
				// 	this.editFormOptions[8].data = ProvinceList;
				// });
				//获取省信息end
				if (this.currentAction == 'Update') {
					if (!this.editFormFields.Province) {
						let list = this.editFormOptions.filter((item) => item.field == 'City' || item.field == 'District');
						list.forEach((item) => (item.readonly = true));
					} else {
						let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=${this.editFormFields.Province}`;
						this.http.post(url, {}).then((result) => {
							let CityList = result.map((a) => {
								return {
									key: a.citys_Id,
									value: a.citys_name
								};
							});
							let arr = this.editFormOptions.filter((item) => item.field == 'City');
							arr.forEach((item) => {
								item.data = CityList;
								item.readonly = false;
							});
						});
					}
					if (!this.editFormFields.City) {
						this.editFormOptions.filter((item) => item.field == 'District')[0].readonly = true;
					} else {
						let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=${this.editFormFields.City}`;
						this.http.post(url, {}).then((result) => {
							let DistrictList = result.map((a) => {
								return {
									key: a.citys_Id,
									value: a.citys_name
								};
							});
							this.editFormOptions.filter((item) => item.field == 'District')[0].data = DistrictList;
						});
					}
				}
				return true;
			},
			cellClick(index, row, column) {
				//单元格击事件(默认触发编辑)
				//仅onInited中设置：this.direction = "horizontal", this.columns的字段设置为click=true后生效
				return true;
			},
			rowButtons(index, row) {
				//列表显示的按钮
				//自定义按钮,仅onInited中设置：this.direction = "list"后生效
				// return [{
				// 	text: "测试",
				// 	icon: "edit-pen",
				// 	type: "primary",
				// 	plain:true,
				// 	shape:"circle",
				// 	disabled: false
				// },{
				// 	text: "删除",
				// 	icon: "trash",
				// 	type: "error",
				// 	plain:true,
				// 	shape:"circle",
				// 	//shape:"",//square、circle
				// 	disabled: false
				// }];
			},
			rowButtonClick(btn, index, row) {
				//列表显示的按钮点击事件
				//    if(btn.text=='删除'){
				// 	this.$toast('删除')
				// }
				console.log('btn,index, row', btn, index, row);
			},
			searchBefore(params) {
				//查询前
				return true;
			},
			updateBefore(formData) {
				//更新保存前操作
				return true;
			},
			addBefore(formData) {
				console.log("formData",formData);
				//新建保存前操作
				return true;
			},
			searchFormOnChange(field, value) {
				//查询弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			},
			editFormOnChange(field, value) {
				//新建编辑弹出框下拉框或日期选中事件
				//if(field=="字段"){}
				// console.log(field, value);
				if (field == 'Province') {
					this.editFormFields.City = null;
					this.editFormFields.District = null;
					let list = this.editFormOptions.filter((item) => item.field == 'City' || item.field == 'District');
					list.forEach((item) => {
						if (item.field == 'City') {
							//获取市列表信息 start
							let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=${value}`;
							this.http.post(url, {}).then((result) => {
								let CityList = result.map((a) => {
									return {
										key: a.citys_Id,
										value: a.citys_name
									};
								});
								item.data = CityList;
							});
							//获取市列表信息 end
							item.readonly = false;
						} else {
							item.readonly = true;
						}
					});
				}
				if (field == 'City') {
					this.editFormFields.District = null;
					let list = this.editFormOptions.filter((item) => item.field == 'District');
					let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=${value}`;
					this.http.post(url, {}).then((result) => {
						let DistrictList = result.map((a) => {
							return {
								key: a.citys_Id,
								value: a.citys_name
							};
						});
						list[0].data = DistrictList;
						list[0].readonly = false;
					});
				}
			},
			modelOpenAfter() {
				//弹出框打开的方法
				// this.currentAction=='Add'//判断是新建还是编辑操作
				// console.log('Open', this.currentAction == 'Add');
				let readOnlyList =  this.editFormOptions.filter((item) =>  item.field == 'Client_type'|| item.field == 'Client_no'|| item.field == 'Character');
				readOnlyList.forEach((item) => (item.readonly = true));
				//获取省信息stater
				if (this.currentAction == 'Add') {
					let list = this.editFormOptions.filter((item) => item.field == 'City' || item.field == 'District'|| item.field == 'Client_type'|| item.field == 'Character'|| item.field == 'Client_flag'|| item.field == 'Display_flag'|| item.field == 'Credit_quota');
					list.forEach((item) => {
						item.readonly = true
						if( item.field == 'Client_type'|| item.field == 'Character'|| item.field == 'Client_flag'|| item.field == 'Display_flag'|| item.field == 'Credit_quota'){
							item.hidden = true
						}
					});
					this.editFormFields.Client_type="0"
					this.editFormFields.Client_flag="1"
					this.editFormFields.Character="3"
					this.editFormFields.Display_flag=1
					this.editFormFields.Credit_quota=10000
				}
				let url = `api/Sys_Dictionary/getcRegionDictionary?sjid=D39479C4-1A27-43BE-8B27-739EB5CEA278`;
				this.http.post(url, {}).then((result) => {
					let ProvinceList = result.map((a) => {
						return {
							key: a.citys_Id,
							value: a.citys_name
						};
					});
					this.editFormOptions.filter((item) => item.field == 'Province')[0].data = ProvinceList;
				});
				//获取省信息end
				if (this.currentAction == 'Add') {
				}
				return true; //返回false不会弹出框
			}
		}
		// watch: {
		// 	currentAction: {
		// 		deep: true,
		// 		handler(newVal, oldVal) {
		// 			console.log('监听', '1，', newVal, '---', '2，', oldVal);
		// 		}
		// 	}
		// }
	};
}
